import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService service= Executors.newFixedThreadPool(5);
        for(int i=0;i<100;i++) {
            int tmp=i;
            service.submit(()-> {
                Thread current=Thread.currentThread();
                System.out.println("hello thread "+tmp+","+current.getName());
            });
        }
        //最好不要立即终止,否则可能任务还没执行完呢,线程就被终止了
        Thread.sleep(2000);
        //把线程池里所有的线程都终止
        service.shutdown();
        System.out.println("程序退出");
    }
}
